﻿using System;
using System.Collections.Generic;
using YXYLCommon;
using System.Data;

namespace Entity
{
    [Serializable]
    /// <summary>
    /// 报表参数
    /// </summary>
    public class BaoBiaoCS : BaseModel
    {
        public BaoBiaoCS()
        {
            this.ID = DbInt.InitNull();
            this.I_BAOBIAOID = DbInt.InitNull();
            this.I_XIANSHISX = DbInt.InitNull();
            this.I_CANSHULX = DbInt.InitNull();
        }

        public DbInt ID { get; set; }

        public DbInt I_BAOBIAOID { get; set; }

        public DbInt I_XIANSHISX { get; set; }

        public DbInt I_CANSHULX { get; set; }

        public string S_CANSHUMC { get; set; }

        public string S_CANSHU { get; set; }

        public string S_CANSHUZLX { get; set; }

        public string S_SHUJUY { get; set; }

        public string S_CANSHUZ { get; set; }

        public string S_MORENZ { get; set; }

        public string S_SHAIXUANTJ { get; set; }

        public string S_MIAOSHU { get; set; }

        public string S_CAOZUOR { get; set; }

        public DbDateTime D_CAOZUOSJ { get; set; }

        public override BaseModel ToObject(System.Data.DataRow row)
        {
            this.IsExists = true;
            this.ID = DbInt.Parse(row["ID"]);
            this.I_BAOBIAOID = DbInt.Parse(row["I_BAOBIAOID"]);
            this.I_XIANSHISX = DbInt.Parse(row["I_XIANSHISX"]);
            this.I_CANSHULX = DbInt.Parse(row["I_CANSHULX"]);
            this.S_CANSHUMC = Convert.ToString(row["S_CANSHUMC"]);
            this.S_CANSHU = Convert.ToString(row["S_CANSHU"]);
            this.S_CANSHUZLX = Convert.ToString(row["S_CANSHUZLX"]);
            this.S_SHUJUY = Convert.ToString(row["S_SHUJUY"]);
            this.S_CANSHUZ = Convert.ToString(row["S_CANSHUZ"]);
            this.S_MORENZ = Convert.ToString(row["S_MORENZ"]);
            this.S_SHAIXUANTJ = Convert.ToString(row["S_SHAIXUANTJ"]);
            this.S_MIAOSHU = Convert.ToString(row["S_MIAOSHU"]);
            this.S_CAOZUOR = Convert.ToString(row["S_CAOZUOR"]);
            this.D_CAOZUOSJ = DbDateTime.Parse(row["D_CAOZUOSJ"]);
            return this;
        }

        public DbType GetDbType()
        {
            if (S_CANSHUZLX == "INT")
            {
                return DbType.Int32;         
            }
            else if (S_CANSHUZLX == "VARCHAR")
            {
                return DbType.String;
            }
            else if (S_CANSHUZLX == "VARCHAR")
            {
                return DbType.String;
            }
            else if (S_CANSHUZLX == "NUMERIC")
            {
                return DbType.Decimal;
            }
            else if (S_CANSHUZLX == "DATETIME")
            {
                return DbType.DateTime;
            }
            else
            {
                return DbType.String;
            }
        }

        public object GetDbValue()
        {
            if (S_CANSHUZLX == "INT")
            {
                return DbInt.Parse(this.S_CANSHUZ).DvalueDBParameter;
            }
            else if (S_CANSHUZLX == "VARCHAR")
            {
                return string.IsNullOrEmpty(this.S_CANSHUZ)?null:this.S_CANSHUZ;
            }
            else if (S_CANSHUZLX == "NUMERIC")
            {
                return DbDecimal.Parse(this.S_CANSHUZ).DvalueDBParameter;
            }
            else if (S_CANSHUZLX == "DATETIME")
            {
                return DbDateTime.Parse(this.S_CANSHUZ).TimeDBParameter;
            }
            else
            {
                return null;
            }
        }
    }

    public class DALBaoBiaoCS : BaseDAL
    {
        public DALBaoBiaoCS()
        {

        }
        protected override void fillSaveProc(BaseModel model)
        {
            BaoBiaoCS obj = (BaoBiaoCS)model;
        }

        //根据名称模糊查询
        public List<BaoBiaoCS> GetByBaoBiaoId(int baobiaoid)
        {
            dbProc.Init("P_YSBB_HUOQUCS");
            dbProc.AddParameter("V_BAOBIAOID", baobiaoid);
            dbProc.AddOracleCursor();
            var baoBiaoCs = CommonService.Ini().GetList<BaoBiaoCS>(dbProc);
            return baoBiaoCs;
        }

        /// <summary>
        /// 多项删除
        /// </summary>
        /// <param name="ids">ID的拼接字符串,形式:'1,2,3'</param>
        public DbCmdResult ListDel(string ids)
        {
            dbProc.Init("P_YSBB_CANSHUDEL");
            dbProc.AddParameter("V_IDS", ids);
            return CommonService.Ini().ExcuteProcOracle(dbProc);
        }

        /// <summary>
        /// 更新参数ID获取参数
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BaoBiaoCS GetById(int id)
        {
            dbProc.Init("CS_SelCX_BAOBIAOC");
            dbProc.AddParameter("V_ID", id);
            dbProc.AddOracleCursor();
            return CommonService.Ini().GetObject<BaoBiaoCS>(dbProc);
        }

        /// <summary>
        /// 保存
        /// </summary>
        public DbCmdResult Save(BaoBiaoCS obj)
        {
            dbProc.Init("P_YSBBCS_SAVE");
            dbProc.AddParameter("V_ID", obj.ID.DvalueDBParameter);
            dbProc.AddParameter("V_I_BAOBIAOID", obj.I_BAOBIAOID.DvalueDBParameter);
            dbProc.AddParameter("V_I_XIANSHISX", obj.I_XIANSHISX.DvalueDBParameter);
            dbProc.AddParameter("V_I_CANSHULX", obj.I_CANSHULX.DvalueDBParameter);
            dbProc.AddParameter("V_S_CANSHUMC", obj.S_CANSHUMC);
            dbProc.AddParameter("V_S_CANSHU", obj.S_CANSHU);
            dbProc.AddParameter("V_S_CANSHUZLX", obj.S_CANSHUZLX);
            dbProc.AddParameter("V_S_SHUJUY", obj.S_SHUJUY);
            dbProc.AddParameter("V_S_CANSHUZ", obj.S_CANSHUZ);
            dbProc.AddParameter("V_S_MORENZ", obj.S_MORENZ);
            dbProc.AddParameter("V_S_SHAIXUANTJ", obj.S_SHAIXUANTJ);
            dbProc.AddParameter("V_S_MIAOSHU", obj.S_MIAOSHU);
            dbProc.AddParameter("V_S_CAOZUOR", obj.S_CAOZUOR);
            dbProc.AddParameter("V_OPERATE", obj.Operate.ToString());
            return CommonService.Ini().ExcuteProcOracle(dbProc);
        }

        public DbCmdResult SAVEORDERS(string ids, string inos)
        {
            dbProc.Init("P_YSBBCS_SAVEORDERS");
            dbProc.AddParameter("IDS", ids);
            dbProc.AddParameter("INOS", inos);
            return CommonService.Ini().ExcuteProcOracle(dbProc);
        }

        //根据名称模糊查询
        public List<DDLItem> GetDDLList(int baobiaoid, int canshubs)
        {
            dbProc.Init("P_YSBB_HUOQUKXCSLB");
            dbProc.AddParameter("V_BAOBIAOID", baobiaoid);
            dbProc.AddParameter("V_CANSHUCX", canshubs);
            dbProc.AddOracleCursor();
            return CommonService.Ini().GetList<DDLItem>(dbProc);
        }

    }

}